﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Peak.Core;
using Peak.Web.Controllers.Models;
using SharpArch.Web.ModelBinder;

namespace Peak.Web.Controllers.Binders
{
  public class StoryFilterModelBinder : SharpModelBinder
  {
    public const string StoryFilterModelConst = "storyFilterModel";

    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
      StoryFilterModel filter = controllerContext.HttpContext.Session[StoryFilterModelConst] as StoryFilterModel;
      if(filter == null)
      {
        controllerContext.HttpContext.Session[StoryFilterModelConst] = filter = new StoryFilterModel();        
      }
      bindingContext.ModelMetadata.Model = filter;
      
      return base.BindModel(controllerContext, bindingContext);
    }
  }
}